/**
 * 
 */
package com.patternity.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents an element (e.g. class or interface)
 * 
 * @author Cyrille.Martraire
 */
// @Entity //identity by name
public class Element {

	private final String name;

	private final List<String> stereotypes = new ArrayList<String>();

	public Element(final String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public List<String> getStereotypes() {
		return stereotypes;
	}

	// Fluent interface
	/**
	 * Add the given stereotype, in insertion order, except if it is already (to
	 * prevent duplicate stereotypes)
	 */
	public Element addSterotype(final String stereotype) {
		if (stereotypes.contains(stereotype)) {
			return this;
		}
		stereotypes.add(stereotype);
		return this;
	}

	@Override
	public int hashCode() {
		return name.hashCode() + 31 * stereotypes.hashCode();
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		final Element other = (Element) obj;
		return name.equals(other.name) & stereotypes.equals(other.stereotypes);
	}

	@Override
	public String toString() {
		return name + " " + stereotypes;
	}
}
